package Actions;

import java.awt.event.ActionEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import javax.swing.JFileChooser;

import view.ViewController;
import view.slogoFile;

public class EditorSaveScript extends AbstractActionPerformed {

	private JFileChooser fileChoose = new JFileChooser(System.getProperty("user.dir"));
	
	@Override
	public void action(ViewController listener, ActionEvent e) {
		int chosen = fileChoose.showSaveDialog(null);
		
		if (chosen == JFileChooser.APPROVE_OPTION)
		{
			File f = fileChoose.getSelectedFile();
		
			try {
				
				
				BufferedWriter writer = new BufferedWriter(new FileWriter(f));
				writer.write(listener.getChildFrame().getContents());
				writer.close();
			}
			catch (Exception ex){
				ex.printStackTrace();
			}
			
		}
	}

}
